package com.randb.easyhttp.callback;

import com.google.gson.internal.$Gson$Types;
import com.randb.easyhttp.model.ApiResult;
import com.randb.easyhttp.utils.Utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.RequestBody;

/**
 * User: RandBII
 * Date: 2020/5/27
 * Description:
 */
public abstract class CallClazzProxy<T extends ApiResult<R>, R> implements IType<T> {

    private Type type;

    public CallClazzProxy(Type type) {
        this.type = type;
    }

    public Type getCallType() {
        return type;
    }


    @Override
    public Type getType() {
        Type typeArgument = null;
        if (type != null) {
            typeArgument = type;
        }
        if (typeArgument == null) {
            typeArgument = RequestBody.class;
        }
        Type rawType = Utils.findNeedType(getClass());
        if (rawType instanceof ParameterizedType) {
            rawType = ((ParameterizedType) rawType).getRawType();
        }
        return $Gson$Types.newParameterizedTypeWithOwner(null, rawType, typeArgument);
    }




}
